import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { ItemData } from "../../resource/info/ItemData";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { BaseItem } from "../common/BaseItem";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ShopEventName } from "./ShopEventName";
import { ShopOperType } from "./ShopOperType";
import { CursorManager } from "../../manager/CursorManager";
import { TItem } from "../../../../Message/Db/Tables/TItem";
type int = number;
//class ItemRender
    
    export  class ItemRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this._unitBitmap = new Object /* flash.display.Bitmap */();
            this.createChildren();
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClickHandler);
            this.doubleClickEnabled = true;
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOver);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOut);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            this.shopItemInfo = arg1["shopItemInfo"] as ShopItemInfo;
            if (this.shopItemInfo && this.shopItemInfo.itemInfo) 
            {
                this._price = this.shopItemInfo.tshopSell.price;
                this._priceType = this.shopItemInfo.unit;
                this.itemInfo = this.shopItemInfo.itemInfo.item;
                loc1 = new ItemData(this.itemInfo.code);
                this._propImage.itemData = loc1;
                this._propImage.drawNow();
                this._propImage.setSize(33, 33);
                this._nameLabel.htmlText = ItemsUtil.getItemName(loc1);
                this._priceNumLabel.htmlText = "<font color=\'#B0EFFF\'>" + this._price + "</font>";
                this._priceImgName = GameDefConfig.instance.getEPrictUnitImg(this._priceType);
                if (this._priceImgName != "") 
                {
                    this._unitBitmap.bitmapData = GlobalClass.getBitmapData(this._priceImgName);
                }
                this.selected = true;
            }
            return;
        }

        /* internal  */createChildren(): void
        {
            this._windowCenterB = ResouceConst.getScaleBitmap("WindowCenterB");
            this._windowCenterB.width = 142;
            this._windowCenterB.height = 40;
            this.addChild(this._windowCenterB);
            this._itemBg = GlobalClass.getBitmap("PropBg");
            this._itemBg.width = 38;
            this._itemBg.height = 38;
            this._itemBg.x = 2;
            this._itemBg.y = 3;
            this.addChild(this._itemBg);
            this._nameLabel = new GLabel();
            this._nameLabel.x = 40;
            this._nameLabel.y = 2;
            this.addChild(this._nameLabel);
            this._priceNumLabel = new GLabel();
            this._priceNumLabel.x = 65;
            this._priceNumLabel.y = 20;
            this.addChild(this._priceNumLabel);
            this._unitBitmap = new Object /* flash.display.Bitmap */();
            this._unitBitmap.x = 40;
            this._unitBitmap.y = 20;
            this.addChild(this._unitBitmap);
            this._clickSprite = new Object /* flash.display.Sprite */();
            this._clickSprite.graphics.beginFill(16711680, 0);
            this._clickSprite.graphics.drawRect(0, 0, 142, 40);
            this._clickSprite.cacheAsBitmap = true;
            this.addChild(this._clickSprite);
            this._clickSprite.doubleClickEnabled = true;
            this._clickSprite.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onItemDoubleClickHandler);
            this._propImage = new BaseItem();
            this._propImage.label = "";
            this._propImage.move(5, 5);
            this.addChild(this._propImage);
            this._propImage.doubleClickEnabled = true;
            this._propImage.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onItemDoubleClickHandler);
            return;
        }

        public onItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShopItemSelect, this.shopItemInfo, true));
            return;
        }

        public onItemDoubleClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispatchEvent(new DataEvent(ShopEventName.ITEM_DOUBLECLICK, this.shopItemInfo, false, true));
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (arg1 && this.itemInfo) 
            {
                this.filters = [new Object /* flash.filters.GlowFilter */(3856353, 1, 6, 6, 1, 1, false, false)];
            }
            else 
            {
                this.filters = [];
            }
            return;
        }

        /* internal  */onMouseOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (ShopOperType.currentOperType == ShopOperType.BUY) 
            {
                CursorManager.showCursor(CursorManager.BUY);
            }
            return;
        }

        /* internal  */onMouseOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            CursorManager.hideCursor();
            return;
        }

        /* internal */ /* var */_clickSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_itemBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_propImage: BaseItem;

        /* internal */ /* var */_priceNumLabel: GLabel;

        /* internal */ /* var */_unitBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_windowCenterB: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_price: int;

        /* internal */ /* var */_priceType: int;

        /* internal */ /* var */_priceImgName: string;

        /* internal */ /* var */shopItemInfo: ShopItemInfo;

        /* internal */ /* var */itemInfo: TItem;
    }
